import Vue from 'vue'
import VueRouter from 'vue-router'
import configRouter from './modules'
import commonRouter from './common'
// import layout from '@/layout/index.vue'

Vue.use(VueRouter)

export const constantRoutes = commonRouter // 无需动态判断权限的路由，如登录页、404等通用页面
export const asyncRoutes = configRouter // 需要动态判断权限并通过addRoutes动态添加的页面

// 更新路由配置
const createRouter = () => new VueRouter({
  // mode: 'history', // 去掉路由地址的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
